<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>编辑管理员</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="/backstage/css/font.css">
    <link rel="stylesheet" href="/backstage/css/xadmin.css">
    <style>
        /* .layui-form-label{
            width:120px;
        } */
    </style>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>
    <div class="x-body">
        <form class="layui-form" >
          <div class="layui-form-item">
              <label for="name" class="layui-form-label">
                  <span class="x-red">*</span>登录名称
              </label>
              <div class="layui-input-inline">
                  <input type="text" id="name" name="name" value="{$info['name']}" lay-verify="required"
                  autocomplete="off" class="layui-input">
              </div>
          </div>
          <div class="layui-form-item">
            <label for="phone" class="layui-form-label">
                <span class="x-red">*</span>手机号码
            </label>
            <div class="layui-input-inline">
                <input type="text" id="phone" name="phone" value="{$info['phone']}" lay-verify="required|phone"
                autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label for="email" class="layui-form-label">
                <span class="x-red">*</span>邮箱地址
            </label>
            <div class="layui-input-inline">
                <input type="text" id="email" name="email" value="{$info['email']}" lay-verify="required|email"
                autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-form-item">
            <label for="role_id" class="layui-form-label">
                <span class="x-red">*</span>选择角色
            </label>
            <div class="layui-input-inline">
                <select name="role_id">
                  {foreach name="role_list" item="row"}
                  <option value="{$row['id']}" {:$row['id']==$info['role_id']?'selected':''}>{$row['role_name']}</option>
                  {/foreach}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label for="ip" class="layui-form-label">
                <span class="x-red"></span>登录 I P
            </label>
            <div class="layui-input-inline">
                <input type="test" class="layui-input" disabled value="{$info['login_ip']}" >
            </div>
        </div>    
        <div class="layui-form-item">
            <label for="password" class="layui-form-label">
                <span class="x-red"></span>修改密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="password" name="password"
                        class="layui-input" lay-verify="password">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="password2" class="layui-form-label">
                <span class="x-red"></span>确认密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="password2" name="password2"
                        class="layui-input" lay-verify="password2">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class="x-red">*</span>状态</label>
            <div class="layui-input-block">
                <input type="radio" name="status" value="1" title="启用" {$info['status']==1?'checked':''}>
                <input type="radio" name="status" value="2" title="禁用" {$info['status']==2?'checked':''}>
            </div>
        </div> 
        <div class="layui-form-item layui-form-text">
                <label for="desc" class="layui-form-label">
                    备注
                </label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入内容" id="comment" name="comment" class="layui-textarea">{$info['comment']}</textarea>
                </div>
            </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
            </label>
            <button  class="layui-btn" lay-filter="upd" lay-submit="" type="button">
                确认提交
            </button>
        </div>
        <input type="hidden" value="{$info['id']}" name="id">
        {:token()}
      </form>
    </div>
    <script type="text/javascript" src="/js/jquery.js"></script>
    <script type="text/javascript" src="/backstage/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/backstage/js/xadmin.js"></script>
    <script>
        layui.use(['form','layer'], function(){
            $ = layui.jquery;
          var form = layui.form
          ,layer = layui.layer;

          //自定义验证规则
          form.verify({
            required: function(value){
                if(value==''){
                    return '此选项不能为空'
                }
            },
            password: function(value){
                if(value != '' && value.length<6){
                    return '密码不能少于6位';
                }
            },
            password2: function(value){
                if($('#password').val()!=$('#password2').val()){
                    return '两次密码不一致';
                }
            }
          
          });
          //监听提交
          form.on('submit(upd)', function(data){
         
            $.post('{:config("template.root_path")}/admin/update/'+data.field.id,data.field,function(res){
                if(res.code=='200'){
                    // 获得frame索引
                     var index = parent.layer.getFrameIndex(window.name);
                    // 关闭当前frame
                     parent.layer.close(index);
                     parent.layer.msg("修改成功", {icon: 6,time:1000});
                     parent.app.getListData();
                     parent.app.page();
                }else{
                    layer.msg(res.msg, {icon: 5,time:1000});
                }
   
            },'json');
     
          });
          
          
        });

    </script>
  </body>
</html>